package routes

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"web_app/controller"
	"web_app/logger"
	"web_app/middlewares"
)

func Setup(mode string) (r *gin.Engine) {
	// 设置成发布模式
	if mode == gin.ReleaseMode {
		gin.SetMode(gin.ReleaseMode)
	}
	r = gin.New()
	r.Use(logger.GinLogger(), logger.GinRecovery(true))
	r.GET("/", func(c *gin.Context) {
		//注册业务路由
		controller.ResponseSuccess(c, nil)
	})
	r.Group("api/v1")
	{
		r.POST("/signup", controller.SingUpHandler)
		r.POST("/login", controller.LoginHandler)
		r.GET("/ping", middlewares.JWTAuthMiddleware(), func(c *gin.Context) {
			isLogin := true

			if isLogin {
				c.String(http.StatusOK, "pong")
			} else {
				c.String(http.StatusOK, "请登录")
			}

		})
	}
	return
}
